<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!-- This test needs process isolation because it creates a subdirectory structure -->
    <!-- in its output folder for the purpose of testing assembly loading. -->
    <RequiresProcessIsolation>true</RequiresProcessIsolation>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="*.cs" />
    <Compile Include="../NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs" />
    <CMakeProjectReference Include="../NativeLibrary/NativeLibraryToLoad/CMakeLists.txt" />
  </ItemGroup>

  <PropertyGroup>
    <LibrarySubdirectory>$(OutputPath)/subdirectory</LibrarySubdirectory>
  </PropertyGroup>

  <Target Name="SetUpSubdirectoryNative" AfterTargets="CopyNativeProjectBinaries">
    <ItemGroup>
      <NativeLibrariesToMove Include="$(OutDir)/libNativeLibrary.*" />
      <NativeLibrariesToMove Include="$(OutDir)/NativeLibrary.*" />
    </ItemGroup>
    <Move SourceFiles="@(NativeLibrariesToMove)" DestinationFiles="@(NativeLibrariesToMove -> '$(LibrarySubdirectory)/%(Filename)%(Extension)')"/>
  </Target>

  <Target Name="SetUpSubdirectoryManaged" AfterTargets="Build">
    <ItemGroup>
      <AssembliesToCopy Include="$(OutDir)/$(TargetName).dll" />
    </ItemGroup>
    <Copy SourceFiles="@(AssembliesToCopy)" DestinationFiles="@(AssembliesToCopy -> '$(LibrarySubdirectory)/%(Filename)%(Extension)')"/>
  </Target>

  <Target Name="SetUpAOTDirectory" Condition="'$(TestBuildMode)' == 'nativeaot'" AfterTargets="Build">
    <ItemGroup>
      <NativeLibrariesToCopy Include="$(LibrarySubdirectory)/libNativeLibrary.*" />
      <NativeLibrariesToCopy Include="$(LibrarySubdirectory)/NativeLibrary.*" />
    </ItemGroup>
    <Copy SourceFiles="@(NativeLibrariesToCopy)" DestinationFiles="@(NativeLibrariesToCopy -> '$(NativeOutputPath)/%(Filename)-in-native%(Extension)')" />
  </Target>
</Project>
